<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<!-- 父组件模板 -->
		<div id="app">
			<cpn @item-click='cpnClick'></cpn>
		</div>
		<!-- 子组件模板 -->
		<template id="cpn">
			<div id="">
				<button v-for="item in categories" type="button" @click="btnClick(item)">{{item.name}}</button>
			</div>
		</template>
		<script src="../js/vue.js"></script>
		<script>
			//1.子组件
			const cpn={
				template:'#cpn',
				data(){
					return{
						categories:[
							{id:'aaa',name:'热门推荐'},
							{id:'bbb',name:'手机数码'},
							{id:'ccc',name:'家用家电'},
							{id:'ddd',name:'数码办公'}
						]
					}
				},
				methods:{
					btnClick(item){
						this.$emit('item-click',item);
						// console.log(item);
					}
				}
			}
			//2.父组件
			const app=new Vue({
				el:'#app',
				data:{
					message:'你好111'
				},
				components:{
					cpn
				},
				methods:{
					cpnClick(item){
						console.log(item)
					}
				}
			})
		</script>
	</body>
</html>
